#pragma once
#include <vector>
#include <string>

#include <WinSock2.h>
#include <Windows.h>
#include <ws2ipdef.h>
#include <iphlpapi.h>

struct adapter_inf
{
    std::string name;       // adapter friendly name
    std::string unicast;    // first unicast address
    std::string gateway;    // first gateway address, may be null
    std::string dns;        // first DNS address, may be null
    IF_LUID     luid;       // LUID of the adapter

    adapter_inf()
    {
        memset(&luid, 0, sizeof(luid));
    }
};

// Test if <s> is an valid IPv4 address string
// NOTE that there should be no space heading or trailing <s>
// e.g. is_ipv4_address("192.168.1.0") == true
// e.g. is_ipv4_address("192.168.1.256") == false
//
bool is_ipv4_address(const std::string& s);

// WinSock initialize
void sock_startup();

// WinSock uninitialize
void sock_cleanup();

//  Retrieve available adapters' information
// <adl>      OUT store the adapters' information on success
//
bool get_adapter_list(std::vector<adapter_inf>& adl);

//  Create or delete a system route table row
//  Emulate system ROUTE ADD/DELETE command with shorter access time
//
// <enable>   IN  true to create and false to delete
// <dst>      IN  destination network address
// <masks>    IN  prefix length of <dst>
// <gateway>  IN  route interface
// <metric>   IN  route metric, optional
//
bool make_route(bool enable,
                char* dst, int masks, const adapter_inf& gateway,
                size_t metric = -1
                );
